#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
int main()
{
    int fd = open("log.txt", O_WRONLY|O_CREAT|O_APPEND, 0666); 
    //int fd = open("log.txt", O_WRONLY|O_CREAT|O_TRUNC, 0666); 
    if(fd == -1)
    {
        perror("open");
        return -1;
    }
    
    const char* msg = "Hello Linux file\n";
    //write(fd, msg, sizeof(msg));
    write(fd, msg, strlen(msg));

    close(fd);
    //review C:fopen
    //FILE* fp = fopen("log.txt", "w");
    //FILE* fp = fopen("log.txt", "a");
    //if(fp == NULL)
    //{
    //    perror("fopen");
    //    return -1;
    //}
    //const char* str = "Hello Linux file\n";
    //fputs(str, fp);
    //fclose(fp);
}
